package org.ztr.saa03chatmodelchatclient.controller;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/10/20 19:28
 * @Description: 测试ChatClient
 * @Version: 1.0
 */

@RestController
public class ChatClientController
{
    private final ChatClient dashScopeChatClient;

    /** zzyybs@126.com
     * ChatClient不支持自动输入，依赖ChatModel对象接口，ChatClient.builder(dashScopeChatModel).build();
     * @param dashScopeChatModel
     */
    public ChatClientController(ChatModel dashScopeChatModel)
    {
        this.dashScopeChatClient = ChatClient.builder(dashScopeChatModel).build();
    }

    @GetMapping("/chatclient/dochat")
    public String doChat(@RequestParam(name = "msg",defaultValue = "2加9等于几") String msg)
    {
        return dashScopeChatClient.prompt().user(msg).call().content();
    }
}